only sensitize Cut if selection contains some editable text, #60975
authorHavoc Pennington <hp@redhat.com>
Tue, 23 Oct 2001 23:35:00 +0000 (23:35 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Tue, 23 Oct 2001 23:35:00 +0000 (23:35 +0000)
2001-10-23  Havoc Pennington  <hp@redhat.com>

* gtk/gtktextview.c (popup_targets_received): only sensitize Cut
if selection contains some editable text, #60975
(gtk_text_view_scroll_to_iter): remove warning about scrolling
prior to map; it should actually be OK to do so in many cases,
it would be nice to warn about scrolling when many lines have
height 0, but I don't know what to do about that. Perhaps
move part of flush_scroll into this function? comment added
to consider this.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtktextview.c

index fd67c8733b56e217a7bba57d8ef5acf3457973b9..7806eeffb91230097e9b98f016ee9f0b40028b10 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2001-10-23  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
+       if selection contains some editable text, #60975
+       (gtk_text_view_scroll_to_iter): remove warning about scrolling
+       prior to map; it should actually be OK to do so in many cases, 
+       it would be nice to warn about scrolling when many lines have
+       height 0, but I don't know what to do about that. Perhaps 
+       move part of flush_scroll into this function? comment added 
+       to consider this.
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (changed_handler): Correctly keep the same
index fd67c8733b56e217a7bba57d8ef5acf3457973b9..7806eeffb91230097e9b98f016ee9f0b40028b10 100644 (file)
@@ -1,3 +1,14 @@
+2001-10-23  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
+       if selection contains some editable text, #60975
+       (gtk_text_view_scroll_to_iter): remove warning about scrolling
+       prior to map; it should actually be OK to do so in many cases, 
+       it would be nice to warn about scrolling when many lines have
+       height 0, but I don't know what to do about that. Perhaps 
+       move part of flush_scroll into this function? comment added 
+       to consider this.
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (changed_handler): Correctly keep the same
index fd67c8733b56e217a7bba57d8ef5acf3457973b9..7806eeffb91230097e9b98f016ee9f0b40028b10 100644 (file)
@@ -1,3 +1,14 @@
+2001-10-23  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
+       if selection contains some editable text, #60975
+       (gtk_text_view_scroll_to_iter): remove warning about scrolling
+       prior to map; it should actually be OK to do so in many cases, 
+       it would be nice to warn about scrolling when many lines have
+       height 0, but I don't know what to do about that. Perhaps 
+       move part of flush_scroll into this function? comment added 
+       to consider this.
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (changed_handler): Correctly keep the same
index fd67c8733b56e217a7bba57d8ef5acf3457973b9..7806eeffb91230097e9b98f016ee9f0b40028b10 100644 (file)
@@ -1,3 +1,14 @@
+2001-10-23  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
+       if selection contains some editable text, #60975
+       (gtk_text_view_scroll_to_iter): remove warning about scrolling
+       prior to map; it should actually be OK to do so in many cases, 
+       it would be nice to warn about scrolling when many lines have
+       height 0, but I don't know what to do about that. Perhaps 
+       move part of flush_scroll into this function? comment added 
+       to consider this.
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (changed_handler): Correctly keep the same
index fd67c8733b56e217a7bba57d8ef5acf3457973b9..7806eeffb91230097e9b98f016ee9f0b40028b10 100644 (file)
@@ -1,3 +1,14 @@
+2001-10-23  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
+       if selection contains some editable text, #60975
+       (gtk_text_view_scroll_to_iter): remove warning about scrolling
+       prior to map; it should actually be OK to do so in many cases, 
+       it would be nice to warn about scrolling when many lines have
+       height 0, but I don't know what to do about that. Perhaps 
+       move part of flush_scroll into this function? comment added 
+       to consider this.
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (changed_handler): Correctly keep the same
index fd67c8733b56e217a7bba57d8ef5acf3457973b9..7806eeffb91230097e9b98f016ee9f0b40028b10 100644 (file)
@@ -1,3 +1,14 @@
+2001-10-23  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
+       if selection contains some editable text, #60975
+       (gtk_text_view_scroll_to_iter): remove warning about scrolling
+       prior to map; it should actually be OK to do so in many cases, 
+       it would be nice to warn about scrolling when many lines have
+       height 0, but I don't know what to do about that. Perhaps 
+       move part of flush_scroll into this function? comment added 
+       to consider this.
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (changed_handler): Correctly keep the same
index fd67c8733b56e217a7bba57d8ef5acf3457973b9..7806eeffb91230097e9b98f016ee9f0b40028b10 100644 (file)
@@ -1,3 +1,14 @@
+2001-10-23  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
+       if selection contains some editable text, #60975
+       (gtk_text_view_scroll_to_iter): remove warning about scrolling
+       prior to map; it should actually be OK to do so in many cases, 
+       it would be nice to warn about scrolling when many lines have
+       height 0, but I don't know what to do about that. Perhaps 
+       move part of flush_scroll into this function? comment added 
+       to consider this.
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (changed_handler): Correctly keep the same
index dedb043293b9d33404a0e0c9cc3210ef0f4bab2e..afd86f2aaf7c96770de38e5d31ad5b46d07707d2 100644 (file)
@@ -1306,6 +1306,11 @@ gtk_text_view_scroll_to_iter (GtkTextView   *text_view,
   gint scroll_inc;
   gint screen_xoffset, screen_yoffset;
   gint current_x_scroll, current_y_scroll;
+
+  /* FIXME why don't we do the validate-at-scroll-destination thing
+   * from flush_scroll in this function? I think it wasn't done before
+   * because changed_handler was screwed up, but I could be wrong.
+   */
   
   g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
   g_return_val_if_fail (iter != NULL, FALSE);
@@ -1317,12 +1322,6 @@ gtk_text_view_scroll_to_iter (GtkTextView   *text_view,
 
   DV(g_print(G_STRLOC"\n"));
   
-  if (!GTK_WIDGET_MAPPED (widget))
-    {
-      g_warning ("gtk_text_view_scroll_to_iter(): calling this function before showing the GtkTextView doesn't make sense, maybe try gtk_text_view_scroll_to_mark() instead");
-      return FALSE;
-    }
-  
   gtk_text_layout_get_iter_location (text_view->layout,
                                      iter,
                                      &rect);
@@ -5476,6 +5475,24 @@ typedef struct
   guint time;
 } PopupInfo;
 
+static gboolean
+range_contains_editable_text (const GtkTextIter *start,
+                              const GtkTextIter *end,
+                              gboolean default_editability)
+{
+  GtkTextIter iter = *start;
+
+  while (gtk_text_iter_compare (&iter, end) < 0)
+    {
+      if (gtk_text_iter_editable (&iter, default_editability))
+        return TRUE;
+      
+      gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
+    }
+
+  return FALSE;
+}                             
+
 static void
 popup_targets_received (GtkClipboard     *clipboard,
                        GtkSelectionData *data,
@@ -5495,7 +5512,8 @@ popup_targets_received (GtkClipboard     *clipboard,
       gboolean have_selection;
       gboolean can_insert;
       GtkTextIter iter;
-
+      GtkTextIter sel_start, sel_end;
+      
       if (text_view->popup_menu)
        gtk_widget_destroy (text_view->popup_menu);
 
@@ -5506,7 +5524,7 @@ popup_targets_received (GtkClipboard     *clipboard,
                                 popup_menu_detach);
       
       have_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
-                                                            NULL, NULL);
+                                                             &sel_start, &sel_end);
       
       gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
                                        &iter,
@@ -5515,7 +5533,9 @@ popup_targets_received (GtkClipboard     *clipboard,
       can_insert = gtk_text_iter_can_insert (&iter, text_view->editable);
       
       append_action_signal (text_view, text_view->popup_menu, GTK_STOCK_CUT, "cut_clipboard",
-                           have_selection);
+                           have_selection &&
+                            range_contains_editable_text (&sel_start, &sel_end,
+                                                          text_view->editable));
       append_action_signal (text_view, text_view->popup_menu, GTK_STOCK_COPY, "copy_clipboard",
                            have_selection);
       append_action_signal (text_view, text_view->popup_menu, GTK_STOCK_PASTE, "paste_clipboard",